<?php
namespace app\parks\controller;
use app\common\controller\HomeCommon;
use think\Request;
use app\parks\model\Parks;
use think\Db;

/**
 * 
 * @author admin
 *
 */
class Parkusers extends HomeCommon
{
	public function __construct(){
		parent::__construct();
		
	}
   

    /**
     * 园区的人员列表
     */
    public function users_list(){
    	
    	if(Request::instance()->isPost()){
	    	$data['parkid']=input('parkid');
	    	
	    	$where=" 1=1 and a.status=1 and b.status=1 ";
	    	if($data['parkid']){
	    		//验证parkid
	    		$result=Parks::check_parks_eg($data['parkid']);
	    		if($result==false){
	    			return json(['errcode'=>'10002','msg'=>'parkid错误！','data'=>[]]);
	    		}else{
	    			$where.=" and a.parkid= ".$data['parkid'];
	    		}
	    	}
	    	
	    	
	    	
	    	$list=db('users_parks')->alias('a')
	    	->field('b.*')
	    	->join('users b','a.user_id=b.id')
	    	->where($where)
	    	->order('b.id desc')
	    	->paginate(15);
	    	$data=[];
	    	foreach ($list as $key=>$val){
	    		$data[$key]=$val;
	    		$data[$key]['token']=lock_url($val['id']);
	    		unset($data[$key]['id']);
	    		
	    	}
	    	return json(['errcode'=>'0','msg'=>'获取成功！','data'=>$data]);
    	}
    }
}
